/**
 * 
 */
package com.alstudio.view.tableview;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alstudio.view.ViewUtils;
import com.alstudio.view.absadapter.ViewAdapter;
import com.loovee.imaohu.R;

/**
 * 用于显示列表中的item项
 * 
 * @author alonso lee
 * 
 */
public class ALBasicListItem extends RelativeLayout {

	private LayoutInflater inflater;
	private Context context;
	public ImageView image;
	public TextView mini_title;
	public TextView title;
	public TextView subtitle;
	public TextView itemCount;
	public ImageView chevron;
	public LinearLayout img_layout;
	private TextView center_msg;

	private boolean useSpecialLayout = false;

	/**
	 * @param context
	 */
	public ALBasicListItem(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		this.context = context;
		init();
	}

	public ALBasicListItem(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.context = context;
		init();
	}

	/**
	 * @param context
	 */
	public ALBasicListItem(Context context, boolean useSpecialLayout) {
		super(context);
		// TODO Auto-generated constructor stub
		this.context = context;
		this.useSpecialLayout = useSpecialLayout;
		init();
	}

	private void init() {
		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		if (useSpecialLayout) {
			inflater.inflate(R.layout.me_user_info_layout, this);
		} else {
			inflater.inflate(R.layout.basic_normal_list_item, this);
		}
		image = (ImageView) findViewById(R.id.image);
		mini_title = (TextView) findViewById(R.id.mini_title);
		title = (TextView) findViewById(R.id.title);
		subtitle = (TextView) findViewById(R.id.subtitle);
		itemCount = (TextView) findViewById(R.id.itemCount);
		chevron = (ImageView) findViewById(R.id.chevron);
		img_layout = (LinearLayout) findViewById(R.id.img_layout);
		center_msg = (TextView) findViewById(R.id.center_msg);
	}

	/**
	 * 设置左边的图标图案
	 * 
	 * @param drawable
	 */
	public void setDrawable(int drawable) {
		this.image.setBackgroundResource(drawable);
	}

	/**
	 * 设置右边箭头
	 */
	public void setChevronImg(int drawable) {
		this.chevron.setImageResource(drawable);
	}

	/**
	 * 显示中间文案
	 * 
	 * @param center_msg
	 *            the center_msg to set
	 */
	public void setCenterMsg(String msg) {
		if (TextUtils.isEmpty(msg)) {
			ViewUtils.goneView(center_msg);
		} else {
			ViewUtils.showView(center_msg);
		}
		ViewUtils.showText(center_msg, msg);
	}

	public void setItemCount(int count) {
		itemCount.setText("" + (count > 99 ? 99 + "+" : count));
		// itemCount.setText("" + count);
		if (count > 0) {
			itemCount.setVisibility(View.VISIBLE);
		} else {
			itemCount.setVisibility(View.GONE);
		}
	}

	public void setItemCount(String str) {
		itemCount.setText(str);
		if (!TextUtils.isEmpty(str)) {
			itemCount.setVisibility(View.VISIBLE);
		} else {
			itemCount.setVisibility(View.GONE);
		}
	}

	public void setItemCountBgRes(int res) {
		itemCount.setBackgroundResource(res);
	}

	public void setItemCountColor(int color) {
		itemCount.setTextColor(color);
	}

	public void setTitleColor(int color) {
		title.setTextColor(color);
	}

}
